#监听键盘按动频率，在目标次数下进行音频提醒
import random

from pynput import keyboard
from playsound import playsound
from threading import Thread

sound_list = ["sound/1.mp3","sound/2.mp3"]
count = 0
# 回调函数
def On_Release(key):
    global count
    print(key)
    count += 1
    if count % 20 == 0:
        # 播放音频
        i = random.randint(0,len(sound_list)-1)
        t = Thread(target=playsound, args=(sound_list[i],))
        t.start()

# 捕获按键（按下或松开）
listener = keyboard.Listener(on_release = On_Release)
listener.start()
listener.join()
